#pragma once
#ifndef Gfx_h__
#define Gfx_h__

#include <stdarg.h>
#include "Geo.h"

///************************************************************************/
/// Pic
///************************************************************************/

typedef void* Pic;

Pic LoadPic(const char* src);
void UnloadPic(Pic pic);
void DrawPic(Pic pic, float x, float y);
void DrawPic(Pic pic, float x, float y, const Color& cl);
void DrawPic(Pic pic, float x, float y, float angle, const Color& cl);

Pic MakePartPic(Pic pic, float x, float y, float w, float h);

void DrawPicPart(Pic pic, float x, float y, float sx, float sy, float w, float h);
void DrawPicPart(Pic pic, float x, float y, float sx, float sy, float w, float h, const Color& cl, float rotation = 0.0f);

float PicWidth(Pic pic);
float PicHeight(Pic pic);

Pic MakeCircle(float radius, const Color& c);
Pic MakeRectangle(float w, float h, const Color& c);

void DrawToPic(Pic pic);
void DrawToScreen();

///************************************************************************/
/// Anim
///************************************************************************/

struct Anim
{
	Vec FrameOffset;
	Vec AnimOffset;
	Pic Img;

	int Frames, Anims;
	inline int FrameID(int tileid) const { return tileid%Frames; }
	inline int AnimID(int tileid) const { return tileid/Frames; }

	/// Loads by default an image with `frames` frames in every row, and `anims` rows
	void Load(const char* src, int frames, int anims);
	/// Loads by default an image with frames and animations where each frame is of size `framesize`
	void Load(const char* src, Vec framesize);
	void Unload();
	void Draw(int anim, int frame, float x, float y);
	void Draw(int anim, int frame, float x, float y, const Color& cl);
	//void Draw(int anim, int frame, float x, float y, float angle);
	//void Draw(int anim, int frame, float x, float y, float angle, const Color& cl);
};

///************************************************************************/
/// Font
///************************************************************************/

typedef void* Fnt;

Fnt LoadFnt(const char* src, int size);
void UnloadFnt(Fnt fnt);
void DrawFnt(Fnt fnt, float x, float y, const Color& cl, const char* format, ...);
void DrawFntBounce( Fnt fnt, float x, float y, const Color& cl, float amplitude, float offset, double faze, const char* format, ... );
void DrawFntCenter(Fnt fnt, float x, float y, const Color& cl, const char* format, ...);
void DrawFntCenterBounce( Fnt fnt, float x, float y, const Color& cl, float amplitude, float offset, double faze, const char* format, ... );
void DrawFntV( Fnt fnt, float x, float y, const Color& cl, const char* format, va_list list );
float TextLength(Fnt fnt, const char* text);
float FntHeight(Fnt fnt);

///************************************************************************/
/// Render
///************************************************************************/

void ClearScr(const Color& cl);

void DrawLine(float x1, float y1, float x2, float y2, const Color& cl, float thickness = 1.0f);
void DrawCircle(float x, float y, float r, const Color& cl, float thickness = 1.0f);
void DrawFilledCircle(float x, float y, float r, const Color& cl);
void DrawFramedCircle(float x, float y, float r, const Color& clBg, const Color& clFr, float thickness = 1.0f);
void DrawArc( float x, float y, float r, float start, float delta, const Color& cl, float thickness );
void DrawRect(float x, float y, float w, float h, const Color& cl, float thickness = 1.0f);
void DrawFilledRect(float x, float y, float w, float h, const Color& cl);
void DrawFramedRect(float x, float y, float w, float h, const Color& clBg, const Color& clFr, float thickness = 1.0f);
void DrawRoundRect(float x, float y, float w, float h, float rx, float ry, const Color& cl, float thickness = 1.0f);
void DrawFilledRoundRect(float x, float y, float w, float h, float rx, float ry, const Color& cl);
void DrawFramedRoundRect(float x, float y, float w, float h, float rx, float ry, const Color& clBg, const Color& clFr, float thickness = 1.0f);
void DrawSpline(Vec p[4], const Color& cl, float thickness = 1.0f);

void DrawQuad(const Vec* pts, Pic pic = 0, const Color& tint = Color::White(), const Vec* uvs = 0);

#endif // Gfx_h__
